package br.com.perkins.myproject.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import br.com.perkins.myproject.domain.Menu;
import br.com.perkins.myproject.domain.Submenu;
import br.com.perkins.myproject.persistence.DaoGenerico;

@Service("submenuService")
@Scope("prototype")
public class SubmenuServiceImpl extends ServiceImpl implements SubmenuService {

	@Resource
	private DaoGenerico <Submenu,Integer> submenuDao;

	@Override
	public Submenu atualizar(Submenu submenu) {
		return submenuDao.atualizar(submenu);
	}

	public SubmenuServiceImpl() {
		super();
	}

	@Override
	public void excluir(Submenu submenu) {
		submenuDao.excluir(submenu);
	}

	@Override
	public Submenu pesquisar(Submenu submenu) {
		return submenuDao.pesquisarPorId(submenu.getId());
	}

	@Override
	public Submenu salvar(Submenu submenu) {
		return submenuDao.salvar(submenu);
	}

	@Override
	public List<Submenu> todos() {
		return submenuDao.todos();
	}

	@Override
	public List<Submenu> todosPorMenu(Menu menu) {
		Map<String, Object> params = new HashMap<String,Object>();
		params.put("id", menu.getId());

    	String query="SELECT s FROM Submenu s WHERE s.menu.id=:id";

		return submenuDao.listPesqParam(query, params);
	}

}
